﻿using Microsoft.Extensions.DependencyInjection;
using Quartz;
using System.Threading.Tasks;
using Zocono.WCS.HangfireHost.TaskJobs;

namespace Zocono.WCS.HangfireHost.QuartzJobs
{
    public class QuartzOnceJobQz : IJob
    {
        private readonly IServiceScopeFactory _serviceScopeFactory;

        public QuartzOnceJobQz(IServiceScopeFactory serviceScopeFactory)
        {
            this._serviceScopeFactory = serviceScopeFactory;
        }

        public async Task Execute(IJobExecutionContext context)
        {
            using (var scope = _serviceScopeFactory.CreateScope())
            {
                var _OnceJobQz = scope.ServiceProvider.GetRequiredService<OnceJobQz>();
                await _OnceJobQz.DoJob();
            }
        }
    }
}
